Sentence in Object Text

Hello,

I have a module with many requirement objects. The module has Requirement column with Yes or No values. Each requirement object has object text that has a sentence consisting of shall word.  The object text, in addition to the sentence with shall, has additional information such as a note, rational/reason etc.  Is there a simple dxl statement to extract requirement sentence portion from the object text and assign the extracted sentence to a variable such as requirement_sentence = extracted sentence,please.

Thanks in advance and best regards,

Mike

 


MikeMelon - Sun Sep 21 23:39:18 EDT 2014

Re: Sentence in Object Text
llandale - Mon Sep 22 15:31:27 EDT 2014

You should be able to use Regular Expressions.  I'm going to scribble something up but not try it.

The problem is defining "Requirement Sentance".

If your requirement statement is always the 1st sentance and ends in an EOL

"A Requirement Sentance is string of characters that contains "shall" and ends with the period '.' character but contains no other periods." 

In RegExp terms this means

  • "shall" must be its own word, we don't want to find "shallow" nor "marshall".  So now we have to define a "word"...
    I think this means some non-alpha character followed by "shall" followed by some non-alpha character.
  • "shall" is case insensitive, "ShaLL" indeed counts.
    [sS][hH][aA][lL][lL]
  •  We want ALL the characters between the periods.
    [^\.]*
  • We want to strip leading white space.  Not sure about this.

So, here we go.  Maybe someone can improve it, especially stripping the leading spaces and making sure EOLs are handled

string sShallRequirement = "([^\\. ]*[^\\.]*[^a-zA-Z][sS][hH][aA][lL][lL][^a-zA-Z][^\\.]*\\.)"
Regexp reShallRequirement = regexp2(sShallRequirement)
print sShallRequirement "\n"

string GetShallRequiremrent(string sParagraph)
{ // Get the shall requirement sentance, if any.

 if (reShallRequirement sParagraph)  //
 then return sParagraph[match 1]
 else return("")
}
void Test(string sParagraph)
{
 string Sentance = GetShallRequiremrent(sParagraph)
 print "[" Sentance "]\t\t<" sParagraph ">\n"
}

Test(" shall8.")
Test(" .I shall not.")
Test(" .I shallow not.")
Test(" .I marshall not.")
Test("xyz.\n I shall not.\n xys.")

-Louie

Re: Sentence in Object Text
MikeMelon - Mon Sep 22 22:27:55 EDT 2014

llandale - Mon Sep 22 15:31:27 EDT 2014

You should be able to use Regular Expressions.  I'm going to scribble something up but not try it.

The problem is defining "Requirement Sentance".

If your requirement statement is always the 1st sentance and ends in an EOL

"A Requirement Sentance is string of characters that contains "shall" and ends with the period '.' character but contains no other periods." 

In RegExp terms this means

  • "shall" must be its own word, we don't want to find "shallow" nor "marshall".  So now we have to define a "word"...
    I think this means some non-alpha character followed by "shall" followed by some non-alpha character.
  • "shall" is case insensitive, "ShaLL" indeed counts.
    [sS][hH][aA][lL][lL]
  •  We want ALL the characters between the periods.
    [^\.]*
  • We want to strip leading white space.  Not sure about this.

So, here we go.  Maybe someone can improve it, especially stripping the leading spaces and making sure EOLs are handled

string sShallRequirement = "([^\\. ]*[^\\.]*[^a-zA-Z][sS][hH][aA][lL][lL][^a-zA-Z][^\\.]*\\.)"
Regexp reShallRequirement = regexp2(sShallRequirement)
print sShallRequirement "\n"

string GetShallRequiremrent(string sParagraph)
{ // Get the shall requirement sentance, if any.

 if (reShallRequirement sParagraph)  //
 then return sParagraph[match 1]
 else return("")
}
void Test(string sParagraph)
{
 string Sentance = GetShallRequiremrent(sParagraph)
 print "[" Sentance "]\t\t<" sParagraph ">\n"
}

Test(" shall8.")
Test(" .I shall not.")
Test(" .I shallow not.")
Test(" .I marshall not.")
Test("xyz.\n I shall not.\n xys.")

-Louie

Hi Louie,

Many, many thanks for your detailed answer and the sample DXL code. Your sample code worked very well without needing any changes.  Your regular expression is very useful and extracted sentences that have shall word, The GetShallRequirement(string sParagraph) function worked well without any changes.

Thanks you so much for quick response.  Later, I will explore implementing the changes to the regular expression as per your suggestions.

Best regards,

Mike

 

 

 

Re: Sentence in Object Text
llandale - Tue Sep 23 11:34:21 EDT 2014

MikeMelon - Mon Sep 22 22:27:55 EDT 2014

Hi Louie,

Many, many thanks for your detailed answer and the sample DXL code. Your sample code worked very well without needing any changes.  Your regular expression is very useful and extracted sentences that have shall word, The GetShallRequirement(string sParagraph) function worked well without any changes.

Thanks you so much for quick response.  Later, I will explore implementing the changes to the regular expression as per your suggestions.

Best regards,

Mike

 

 

 

You are going to run into nuance problems; keep track of them and will fix it.

Re: Sentence in Object Text
Wolfgang Uhr - Wed Sep 24 04:06:31 EDT 2014

llandale - Mon Sep 22 15:31:27 EDT 2014

You should be able to use Regular Expressions.  I'm going to scribble something up but not try it.

The problem is defining "Requirement Sentance".

If your requirement statement is always the 1st sentance and ends in an EOL

"A Requirement Sentance is string of characters that contains "shall" and ends with the period '.' character but contains no other periods." 

In RegExp terms this means

  • "shall" must be its own word, we don't want to find "shallow" nor "marshall".  So now we have to define a "word"...
    I think this means some non-alpha character followed by "shall" followed by some non-alpha character.
  • "shall" is case insensitive, "ShaLL" indeed counts.
    [sS][hH][aA][lL][lL]
  •  We want ALL the characters between the periods.
    [^\.]*
  • We want to strip leading white space.  Not sure about this.

So, here we go.  Maybe someone can improve it, especially stripping the leading spaces and making sure EOLs are handled

string sShallRequirement = "([^\\. ]*[^\\.]*[^a-zA-Z][sS][hH][aA][lL][lL][^a-zA-Z][^\\.]*\\.)"
Regexp reShallRequirement = regexp2(sShallRequirement)
print sShallRequirement "\n"

string GetShallRequiremrent(string sParagraph)
{ // Get the shall requirement sentance, if any.

 if (reShallRequirement sParagraph)  //
 then return sParagraph[match 1]
 else return("")
}
void Test(string sParagraph)
{
 string Sentance = GetShallRequiremrent(sParagraph)
 print "[" Sentance "]\t\t<" sParagraph ">\n"
}

Test(" shall8.")
Test(" .I shall not.")
Test(" .I shallow not.")
Test(" .I marshall not.")
Test("xyz.\n I shall not.\n xys.")

-Louie

It is wounderful Louie, I did not understand the question and you gave the correct answer in the first shoot.

Re: Sentence in Object Text
llandale - Wed Sep 24 13:51:19 EDT 2014

Wolfgang Uhr - Wed Sep 24 04:06:31 EDT 2014

It is wounderful Louie, I did not understand the question and you gave the correct answer in the first shoot.

I had this exact problem some years ago and failed.  So I recognized it.  I was trying to hard-code the solution and recall numerous nuances that complicated it a lot; shallow and marshall coming to mind.

Only took me 4 years to become RegExp literate.  Even so, I still must go back to the manual and my library examples in order to talk about it.

-Louie